﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using StyleMVVM.Data.Activation;
using StyleMVVM.DependencyInjection;
using StyleMVVM.Utilities;

namespace StyleMVVM.Logging
{
	public sealed class LogService : ILogService, IDependencyInjectionContainerAware, IActivationAware
	{
		public static void RegisterExport(IDependencyInjectionContainer container)
		{
			container.Register(typeof(LogService)).As(typeof(ILogService))
			         .WithPriority(-1).AndSharedPermenantly();
		}

		public ILog DefaultLog { get; set; }

		public ILog GetLogger(string loggerName)
		{
			return DefaultLog;
		}

		public IDependencyInjectionContainer Container { get; set; }

		public void Activate()
		{
			DefaultLog = Container.LocateByType(typeof(ILog)) as ILog;

			if (DesignMode.IsEnabled)
			{
				DefaultLog.LoggingLevel = LogLevel.DEBUG;
			}
		}
	}
}